

#define CoreCallRestoreValues()      CoreCallValues( .bRestore = true )

#define PM_FUNC_NORM_ATTRIB
#define PM_FUNC_PUBLIC_ATTRIB        public
#define PM_FUNC_STOCK_ATTRIB         stock

#define PlayerToName(%1)             NumToName( LIST_PLAYERS, %1 )
#define PokeToName(%1)               NumToName( LIST_POKEMON, %1 )
#define PokeNumToName(%1)            NumToName( LIST_POKEMON_NICKNAMES, %1 )
#define ItemToName(%1)               NumToName( LIST_ITEMS, %1 )
#define SkillToName(%1)              NumToName( LIST_SKILLS, _:%1 )
#define LocationToName(%1)           NumToName( LIST_LOCATIONS, %1 )
#define StatusToName(%1)             NumToName( LIST_STATUS, _:%1 )
#define TypeToName(%1)               NumToName( LIST_POKETYPE, _:%1 )
#define PlayerStatToName(%1)         NumToName( LIST_STAT, _:%1 )

#define NameToPlayer(%1)             NameToNum( LIST_PLAYERS, %1 )
#define NameToPoke(%1)               NameToNum( LIST_POKEMON, %1 )
#define NameToPokeNum(%1)            NameToNum( LIST_POKEMON_NICKNAMES, %1 )
#define NameToItem(%1)               NameToNum( LIST_ITEMS, %1 )
#define NameToSkill(%1)              POKESKILL:NameToNum( LIST_SKILLS, %1 )
#define NameToLocation(%1)           NameToNum( LIST_LOCATIONS, %1 )
#define NameToStatus(%1)             PM_STATUS:NameToNum( LIST_STATUS, %1 )
#define NameToType(%1)               PM_TYPE:NameToNum( LIST_POKETYPE, %1 )
#define NameToPlayerStat(%1)         PM_STAT:NameToNum( LIST_STAT, %1 )

#define SoundSpeak(%1,%2)            client_cmd( %1, "spk %s", gSounds[ %2 ] )
#define SoundEmit(%1,%2)             emit_sound( %1, CHAN_VOICE, gSounds[ %2 ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM )

#define SoundCast(%1)                SoundEmit( %1, SOUND_CAST )
#define SoundCure(%1)                SoundEmit( %1, SOUND_CURE )
#define SoundDeny(%1)                SoundSpeak( %1, SOUND_DENY )
#define SoundHit(%1)                 SoundEmit( %1, SOUND_HIT )
#define SoundPokeCenter(%1)          SoundEmit( %1, SOUND_POKECENTER )

#define LoopThroughPlayersFlags(%1,%2) for ( new %1_i, %1_iPlayers[32], %1_iPnum, %1 = get_players(%1_iPlayers, %1_iPnum, %2); ( ( %1_i < %1_iPnum ) && ( %1 = %1_iPlayers[ %1_i ] ) ); %1_i++ )

#if !defined is_num_odd
	#define is_num_odd(%1)           ( (%1) & 1 )
#endif

#define ValidData(%1)                ( %1[0] != EOS && %1[0] != ';' && !( %1[0] == '/' && %1[1] == '/' ) )

#define SECONDS_TO_SCREENFADE_UNITS(%1) floatround( float( ( 1 << 12 ) ) * (%1) )

#define is_weapon_gun(%1)            !( ( 1 << (%1) ) & ( ( 1 << CSW_KNIFE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_SMOKEGRENADE ) | ( 1 << CSW_C4 ) ) )

#if defined POKEMOD_ADV_DEBUG

	#if defined POKEMOD_ADV_DEBUG_MULT
		new String:szDateTime[ 64 ];
		new Array:iSuffixArray = Invalid_Array;
		new Trie:iSuffixTrie = Invalid_Trie;
	#endif

	new String:szAdvDebugFile[ 128 ];
	PM_FUNC_NORM_ATTRIB pokemod_advdebug_file( String:szSuffix[ 32 ] = "" )
	{
		#if defined POKEMOD_ADV_DEBUG_MULT

			if ( szDateTime[0] == EOS )
			{
				format_time( szDateTime, charsmax(szDateTime), "%Y_%m_%d_%H_%M" );
			}

			new String:szDateFile[ 64 ];
			formatex( szDateFile, charsmax(szDateFile), "/PM_%s-%s.log", szDateTime, szSuffix );

			get_localinfo( "amx_logdir", szAdvDebugFile, charsmax(szAdvDebugFile) );
			add( szAdvDebugFile, charsmax(szAdvDebugFile), szDateFile );

			if ( iSuffixTrie == Invalid_Trie )
			{
				iSuffixTrie = TrieCreate();
				iSuffixArray = ArrayCreate( 32, 1 );
			}
			else
			{
				if ( TrieKeyExists( iSuffixTrie, szSuffix ) )
					return;
			}

			TrieSetCell( iSuffixTrie, szSuffix, 1 );
			ArrayPushString( iSuffixArray, szSuffix );

		#else

			if ( szAdvDebugFile[0] == EOS )
			{
				#pragma unused szSuffix
				new String:szDateTime[ 64 ];
				formatex( szDateTime, charsmax(szDateTime), "/PM_%%Y_%%m_%%d_%%H_%%M.log" );
				format_time( szDateTime, charsmax(szDateTime), szDateTime );

				get_localinfo( "amx_logdir", szAdvDebugFile, charsmax(szAdvDebugFile) );
				add( szAdvDebugFile, charsmax(szAdvDebugFile), szDateTime );
			}

		#endif
	}
	new Int:iFuncLevel, String:szLogMessage[ 128 ];
	PM_FUNC_NORM_ATTRIB pokemod_funcstart_debug( String:szFunc[], any:... )
	{
		#if defined POKEMOD_ADV_DEBUG_MULT
		if ( !iFuncLevel )
		{
			static String:szSuffix[ 32 ];
			copyc( szSuffix, charsmax(szSuffix), szFunc, ' ' );
			pokemod_advdebug_file( szSuffix );
			if ( file_exists( szAdvDebugFile ) )
				delete_file( szAdvDebugFile );
		}
		#else
		if ( !iFuncLevel )
			delete_file( szAdvDebugFile );
		#endif

		arrayset( szLogMessage, ' ', iFuncLevel );
		new Int:iLen = formatex( szLogMessage[ iFuncLevel ], charsmax(szLogMessage) - iFuncLevel, "%d+", iFuncLevel )
		vformat( szLogMessage[ iFuncLevel + iLen ], charsmax(szLogMessage) - iFuncLevel - iLen, szFunc, 2 );
		write_file( szAdvDebugFile, szLogMessage, -1 );

		iFuncLevel++;
	}
	PM_FUNC_NORM_ATTRIB pokemod_funcend_debug( String:szFunc[], any:... )
	{
		iFuncLevel--;

		arrayset( szLogMessage, ' ', iFuncLevel );
		new Int:iLen = formatex( szLogMessage[ iFuncLevel ], charsmax(szLogMessage) - iFuncLevel, "%d-", iFuncLevel )
		vformat( szLogMessage[ iFuncLevel + iLen ], charsmax(szLogMessage) - iFuncLevel - iLen, szFunc, 2 );
		write_file( szAdvDebugFile, szLogMessage, -1 );
	}
	PM_FUNC_NORM_ATTRIB pokemod_advdebug_end()
	{
		#if defined POKEMOD_ADV_DEBUG_MULT
			if ( !iFuncLevel )
			{
				for ( new Int:iSuffix = 0, Int:iSuffixes = ArraySize( iSuffixArray ), String:szTempSuffix[ 32 ];
					iSuffix < iSuffixes;
					iSuffix++
				){
					ArrayGetString( iSuffixArray, iSuffix, szTempSuffix, charsmax(szTempSuffix) );
					pokemod_advdebug_file( szTempSuffix );
					delete_file( szAdvDebugFile );
				}
			}
		#else
			if ( !iFuncLevel )
			{
				delete_file( szAdvDebugFile );
			}
		#endif
	}
#else
	#define pokemod_advdebug_file(%1
	#define pokemod_funcstart_debug(%1
	#define pokemod_funcend_debug(%1
	#define pokemod_advdebug_end(%1
#endif

#if defined POKEMOD_DEBUG
	#define pokemod_debug(%1)        log_amx(%1)
#else
	#define pokemod_debug(%1
#endif

